home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Telnet 2.6.1d1 4⁄26⁄94 Folder / source / depend.perl < prev    next >
Text File  |  1993-09-29  |  3KB  |  138 lines

  1. #
  2. # depend.perl
  3. #
  4. # Copyright 1993,
  5. # Rick Watson
  6. # The University of Texas at Austin
  7. # Networking Services
  8. # r.watson@utexas.edu
  9. #
  10. # usage: perl depend.perl <makefile> <cpp directory> <obj directory> <files...>
  11. #
  12.  
  13. #
  14. # Here's a partial example of usage:
  15. # Make sure you have created cpp and obj directories.
  16. #
  17. #    CPP = ∂
  18. #        :cpp:debug.cpp ∂
  19. #        :cpp:sysheaders.cpp ∂
  20. #        :cpp:configure.cpp ∂
  21. #        :cpp:prefs.cpp ∂
  22. #        :cpp:Sets.cpp ∂
  23. #        :cpp:binsubs.cpp
  24. #    
  25. #    # default rule for relating object files to source files
  26. #    :cpp: ƒ ∂
  27. #        : ∂
  28. #        :config: ∂
  29. #        :ftp: ∂
  30. #        :init: ∂
  31. #        :main: ∂
  32. #        :network: ∂
  33. #        :network:mactcp: ∂
  34. #        :tek: ∂
  35. #        :vr: ∂
  36. #        :vs:
  37. #    
  38. #    # Rule to build .cpp preprocessor output files. Syntax check only and write cpp output.
  39. #    .cpp ƒ .c
  40. #        C "{DepDir}{Default}.c" -e2 -c {COptions} > "{TargDir}{Default}.cpp"
  41. #        
  42. #    depend ƒ {CPP}
  43. #        perl {mpw}local:depend.perl Makefile ":cpp:" ":obj:" {CPP}
  44. #        Rename -y Makefile Makefile.bak
  45. #        Rename -y Makefile.new Makefile
  46. #        Echo "Include ∂"Makefile.bak∂" 'ckid';" | Rez -m -a -o "Makefile" #Transfer the ckid
  47. #    
  48.  
  49. #
  50. # Copy Makefile up to the dependancies line
  51. #
  52. if ($#ARGV < 4) {
  53.     die "depend: not enough arguments\n";
  54. }
  55. $makefile = $ARGV[0];
  56. $cppdir = $ARGV[1];
  57. $objdir = $ARGV[2];
  58.  
  59. open (INPUT, "$makefile") || die "Could not open $makefile\n";
  60. open (OUTPUT, ">$makefile.new") || die "Could not create $makefile.new\n";
  61. while (<INPUT>) {
  62.     if (/^# DO NOT DELETE THIS LINE -- mkdep uses it./) {
  63.         last;
  64.     }
  65.     printf OUTPUT "%s", $_;
  66. }
  67. close (INPUT);
  68.  
  69. print OUTPUT "# DO NOT DELETE THIS LINE -- mkdep uses it.\n";
  70. print OUTPUT "# DO NOT PUT ANYTHING AFTER THIS LINE. IT WILL GO AWAY.\n";
  71. print OUTPUT "\n";
  72.  
  73. #
  74. # process input files
  75. #
  76. for ($ii = 3; $ii <= $#ARGV; $ii++) {
  77.     do depend($ARGV[$ii]);
  78. }
  79.  
  80. print OUTPUT "\n";
  81. print OUTPUT "# IF YOU PUT ANYTHING HERE IT WILL GO AWAY\n";
  82. print OUTPUT "\n";
  83. close (OUTPUT);
  84.  
  85. #
  86. # depend a file
  87. #
  88. # The hardwired paths of :cpp: and :objs: are kinf of a hack. 
  89. # Should try to improve this.
  90. #
  91. sub depend {
  92.  
  93.     undef(%includes);
  94.     
  95.     $cppfilename = $_[0];
  96.     $filename = substr("$cppfilename", 0, length("$cppfilename")-4); # remove .cpp
  97.     $filename = substr("$filename", length($cppdir)); # remove :cpp:
  98.     
  99.     open (FILE, ":cpp:$cppfilename") || die "Can't open input file :cpp:$cppfilename\n";
  100.     
  101.     while (<FILE>) {
  102.         #
  103.         # search for file references in the preprocessor output
  104.         #
  105.         if (/^#line \d* \"(.*)\"/) {
  106.             $includes{$1} = 1;
  107.             next;
  108.         }
  109.         if (/^include \"(.*)\"/) {
  110.             $includes{$1} = 1;
  111.             next;
  112.         }
  113.         if (/^#pragma load \"(.*)\"/) {
  114.             $includes{$1} = 1;
  115.             next;
  116.         }
  117.     }
  118.     close (FILE);
  119.     
  120.     #
  121.     # enumerate the references accumulated in $includes
  122.     #
  123.     $nf = 0;
  124.     while (($key,$val) = each %includes) {
  125.         $_ = $key;
  126.         if (!(/MPW:Interfaces:CIncludes/)) {
  127.             print OUTPUT "$objdir$filename.c.o ƒ \"$key\"\n";
  128.             $nf++;
  129.         }
  130.     }
  131.     if ($nf == 0) {
  132.         print "No dependancies found in $filename\n";
  133.     } else {
  134.         print OUTPUT "\n";
  135.     }
  136. }
  137.  
  138.